package org.agora.games.bodybuilder;

import org.agora.games.bodybuilder.geometry.FixtureDefinition;
import svg.parser.Vertex;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author : Arash Bizhanzadeh <arash.bizhanzadeh@cbc.ca>
 *         Date: 12-01-04
 *         Time: 12:25 AM
 *         CBC.ca All rights reserved.
 */
public class Triangularizer {
    ArrayList<Vertex> vertexes;

    public Triangularizer(ArrayList<Vertex> v) {
        vertexes = v;
    }

    public FixtureDefinition calculate() {
        List<FixtureDefinition> result = new ArrayList<FixtureDefinition>();
        //calculate the middle
        float sumX = sumX(vertexes);
        float sumY = sumY(vertexes);
        float centerX = sumX / vertexes.size();
        float centerY = sumY / vertexes.size();
        return new FixtureDefinition(new Vertex(centerX,centerY), vertexes, 1,1,1);

    }

    private float sumX(List<Vertex> vertexes) {
        float result = 0;
        for (Vertex v : vertexes) {
            result += v.x;
        }
        return result;
    }

    private float sumY(List<Vertex> vertexes) {
        float result = 0;
        for (Vertex v : vertexes) {
            result += v.y;
        }
        return result;
    }

}
